﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SDT.Admin.ViewModels.UserAdministration.IndexViewModel>" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="SDT.Lib.Helpers" %>
<%@ Import Namespace="SDT.Lib.Paging" %>
<%@ Import Namespace="SDT.Model" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Người dùng
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server">
	Người dùng
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="Toolbar" runat="server">
	<%= Html.Toolbar("Thêm mới", "/Account/Register", "new")%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Message" runat="server">
<%=ViewData["MessageInfo"]!=null? "<p class='perror'>"+Html.Encode(ViewData["MessageInfo"])+"</p>":string.Empty%> 
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" runat="server">
<%if (ViewData["MessageInfo"] == null)
  { %>
<% if (Model.Users.Count > 0)
   { %>
    <form action="/UserAdministration/Index" method="post" name="adminForm">
    <table width="100%">
		<tr>
		    <td align="left">
		        Tìm nhanh <%= Html.TextBox("FilterName", Model.FilterName)%>
		        <%= Html.ActionImageJS("Tìm kiếm", "icon-32-search.png", "document.adminForm.submit();")%>
		    </td>
		</tr>
	</table>
    <table class="adminlist">
        <thead>
            <tr>
                <th width="5%">#</th>
                <th width="20%" align="center">
                    Tên đăng nhập
                </th>
                <th width="18%" align="center">
                    Họ và tên
                </th>
                <th width="20%" align="center">
                    Công ty
                </th>
                <th width="10%" align="center">
                    Yahoo
                </th>
                <th width="10%" align="center">
                    Email
                </th>
                <th width="10%" align="center">
                    Đã được bật
                </th>
                <th width="5%" align="center">Xóa</th>
            </tr>
        </thead>
        <tbody>
        <%
    int index = Model.Users.PageIndex * Model.Users.PageSize;
    foreach (var user in Model.Users)
    {
        index++;
        var profile = UserProfile.GetUserProfile(user.UserName);
        %>
            <tr>
                <td><%= index.ToString()%></td>
                <td>
                    <span class="username"><% =Html.ActionLink(user.UserName, "Details", new { id = user.ProviderUserKey })%></span>
                </td>
                <td>
                    <%= profile != null ? Html.Encode(profile.FullName) : ""%>
                </td>
                <td>
                    <%= profile != null ? Html.Encode(profile.Company) : ""%>
                </td>
                <td>
                    <%= profile != null ? Html.Encode(profile.NicYahoo) : ""%>
                </td>
                <td>
                    <span class="email"><a href="mailto:<% =Html.Encode(user.Email) %>"><% =Html.Encode(user.Email)%></a></span>
                </td>
                <td align="center">
			        <img src="/Images/<% =(user.IsApproved ? "tick.png" : "publish_x.png") %>" alt="<% =(user.IsApproved ? "Đã được kích hoạt" : "Chưa kích hoạt") %>" />
		        </td>
                <td align="center">
                    <% using (Html.BeginForm("DeleteUser", "UserAdministration", new { id = user.ProviderUserKey }, FormMethod.Post))
                       { %>
			            <input type="submit" value="Xóa" />
		            <% } %>
		        </td>
            </tr>
        <%            
    }              
        %>
        </tbody>
	</table>
	<table width="100%">
        <tfoot>
            <tr>
                <td align="center">        
                   
                       <div class="pager">
                        <label>Hiển thị #</label>
                            <%
                                int[] pageSizeList = {1, 5, 10, 15, 20, 25, 50, 100};
                            %>
                            <%= Html.DropDownList("pageSize", new SelectList(pageSizeList, Model.Users.PageSize), new { onchange = "document.adminForm.submit();" })%>

                             <%= Html.Pager(Model.Users.PageSize, Model.Users.PageNumber, Model.Users.TotalItemCount, new { pageSize = Model.Users.PageSize })%>
                        </div>                       
                    
                </td>
            </tr>
        </tfoot>
    </table>	
  </form>
    <div style="display:none">
    <% using(Html.BeginForm("CreateRole", "UserAdministration")){ %>
		<fieldset>
			<label for="id">Thêm quyền:</label>
			<% =Html.TextBox("id") %>
			<input type="submit" value="Tạo quyền mới" />
		</fieldset>
	<% } %>
	</div>
<% }
   else
   { %>
	<p>Không có người dùng nào được đăng ký.</p>
<% } %>
<%} %>
</asp:Content>